package com.tedu.interceptor.config;


import com.tedu.interceptor.interceptor.MyInterceptor;
import com.tedu.interceptor.interceptor.MyInterceptor1;
import com.tedu.interceptor.interceptor.MyInterceptor2;
import com.tedu.interceptor.interceptor.MyInterceptor3;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Config implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器

        // 全部无差别拦截
        //registry.addInterceptor(new MyInterceptor());
        // 拦截指定一个路径
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg");*/
        // 拦截指定多个路径
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg","/index.html");*/

        // 拦截指定父路径 匹配所有子路径 /users/** 分模块进行拦截
       /* registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**")
                .excludePathPatterns("/users/login");// 排除指定路径*/

        // 添加多个拦截器
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
        registry.addInterceptor(new MyInterceptor3());

    }
}
